import request from '@/utils/request.js'

/**
 * 用户登录
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userLogin = (data) => {
  return request.post('/user/login', data)
}

/**
 * 用户登出
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userLogout = () => {
  return request.post('/user/logout')
}

/**
 * 用户分页查询
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const pageQueryUser = (data) => {
  return request.post('/user/page', data)
}

/**
 * 保存用户
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const saveUser = (data) => {
  return request.post('/user', data)
}

/**
 * 删除用户
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const deleteUser = (data) => {
  return request.delete('/user', {data})
}

/**
 * 获取用户详情
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getUser = (id) => {
  return request.get(`/user/${id}`)
}

/**
 * 编辑用户
 */
export const updateUser = (data) => {
  return request.put('/user', data)
}

/**
 * 获取所有在线用户
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getAllOnlineUser = () => {
  return request.get('/user/online')
}

/**
 * 下线用户
 * @param token
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const offlineUser = (token) => {
  return request.delete(`/user/online/${token}`)
}
